<?php
/**
 * 个人信息类
 * @author zhanghui
 * @create_date 2008-02-29
 */
class BabyInfo{
	function __construct(){}
	function __destruct(){}
	
	/**
	 *  增加个人信息
	 * @param :$conn 数据库连接类
     * @param  array $arr_input - baby_id,baby_name,friend_cnt,integral,visit_cnt,
     *                             vitality_cnt,fame_cnt,charm_cnt,warm_cnt,create_date
     */
	function addBabyInfo($conn,$arr_input){
		$str_query = "insert into";
		$str_query .= " baby_info";
		$str_query .= " set";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= ",baby_name={$arr_input['baby_name']}";
		$str_query .= ",create_date='".$conn->getCurrentTime()."'";
		
		$conn->executeQuery($str_query);
	}
	
	/**
	 *  删除个人信息
	 * @param :$conn 数据库连接类
     * @param  array $arr_input - baby_id,baby_name,friend_cnt,integral,visit_cnt,
     *                             vitality_cnt,fame_cnt,charm_cnt,warm_cnt,create_date
     */
	function deleteBabyInfo($conn,$arr_input){
		$str_query = "delete from";
		$str_query .= " baby_info";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		
		$conn->executeQuery($str_query);
	}
	
	/**
	 *  更新个人信息
	 * @param :$conn 数据库连接类
     * @param  array $arr_input - baby_id,baby_name,friend_cnt,integral,visit_cnt,
     *                             vitality_cnt,fame_cnt,charm_cnt,warm_cnt,create_date
     */
	function increaseBabyInfo($conn,$arr_input){
		$str_query = "update";
		$str_query .= " baby_info";
		$str_query .= " set";
		$str_query .= " baby_name='{$arr_input['baby_name']}'";
		if(isset($arr_input['friend_cnt'])){
			$str_query .= " and friend_cnt=friend_cnt+{$arr_input['friend_cnt']}";
		}
		if(isset($arr_input['integral'])){
			$str_query .= " and integral=integral+{$arr_input['integral']}";
		}
		if(isset($arr_input['visit_cnt'])){
			$str_query .= " and visit_cnt=visit_cnt+1";
		}
		if(isset($arr_input['vitality_cnt'])){
			$str_query .= " and vitality_cnt=vitality_cnt+{$arr_input['vitality_cnt']}";
		}
		if(isset($arr_input['fame_cnt'])){
			$str_query .= " and fame_cnt=fame_cnt+{$arr_input['fame_cnt']}";
		}
		if(isset($arr_input['charm_cnt'])){
			$str_query .= " and charm_cnt=charm_cnt+{$arr_input['charm_cnt']}";
		}
		if(isset($arr_input['warm_cnt'])){
			$str_query .= " and warm_cnt=warm_cnt+{$arr_input['warm_cnt']}";
		}
		$arr_input .= " where";
		$arr_input .= " baby_id={$arr_input['baby_id']}";
		
		$conn->executeQuery($str_query);
	}
	
	/**
	 *  获取个人信息
	 * @param :$conn 数据库连接类
     * @param  array $arr_input - baby_id,baby_name,friend_cnt,integral,visit_cnt,
     *                             vitality_cnt,fame_cnt,charm_cnt,warm_cnt,create_date
     * @param string $limit 
     * @return : $arr_output
     *			  baby_id, 			    [0]<br>
     *			  baby_name, 		    [1]<br>
     *			  friend_cnt, 			[2]<br>
     *			  integral, 		    [3]<br>
     *			  visit_cnt, 		    [4]<br>
     *			  vitality_cnt, 		[5]<br>
     *			  fame_cnt, 		    [6]<br>
     *			  charm_cnt, 		    [7]<br>
     *			  warm_cnt, 		    [8]<br>
     *			  create_date, 		    [9]<br>
     */
	function getBabyInfoList($conn,$arr_input,$limit = null){
		$str_query = "select";
		$str_query .= " baby_id";
		$str_query .= ",baby_name";
		$str_query .= ",friend_cnt";
		$str_query .= ",integral";
		$str_query .= ",visit_cnt";
		$str_query .= ",vitality_cnt";
		$str_query .= ",fame_cnt";
		$str_query .= ",charm_cnt";
		$str_query .= ",warm_cnt";
		$str_query .= ",create_date";
		$str_query .= " from";
		$str_query .= " baby_info";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		
		$arr_output = $conn->selectQuery($str_query);
		return $arr_output;
	}
}
?>